package pl.edu.pk.mech.kkbus.component;

import com.google.appengine.api.urlfetch.HTTPMethod;
import com.google.appengine.api.urlfetch.HTTPRequest;
import com.google.appengine.api.urlfetch.URLFetchService;
import com.google.appengine.api.urlfetch.URLFetchServiceFactory;

import java.net.URL;

import org.springframework.stereotype.Component;

@Component
public class ExternalEmailSender {

    public boolean send(String to, String subject, String message) {
    
        URLFetchService fetcher = URLFetchServiceFactory.getURLFetchService();
        
        try {
            HTTPRequest request = new HTTPRequest(new URL("http://jackson.netserwer.pl/kkbus/"), HTTPMethod.POST);
            String body = "to=" + to + "&subject=" + subject + "&message=" + message;
            request.setPayload(body.getBytes());
            fetcher.fetch(request);
        } catch (Exception e) {
            return false;
        } finally {
            return true;
        }       
        
    }
    
}
